package com.li.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.li.mapper.ActivityMapper;
import com.li.pojo.dto.ActicityPageDto;
import com.li.pojo.po.Activity;
import com.li.pojo.po.PageResult;
import com.li.service.ActivityService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

@Service
public class ActivityServiceImpl implements ActivityService {
    @Autowired
    ActivityMapper activityMapper;
    @Override
    public PageResult list(ActicityPageDto pageDto) {
        Page<Activity> page = PageHelper.startPage(pageDto.getPageNum(), pageDto.getPageSize());
//        if (pageDto.test()){
//            activityMapper.pagelist(pageDto.getPageNum(), pageDto.getPageSize(),pageDto.getCode(),pageDto.getChannel(),null,null,null,null);
//        }else {
            activityMapper.pagelist(pageDto.getPageNum(), pageDto.getPageSize(),pageDto.getCode(),pageDto.getChannel(),pageDto.getParams().get("beginCreateTime"),pageDto.getParams().get("beginTime"),pageDto.getParams().get("endTime"),pageDto.getParams().get("endCreateTime"));
//        }
        PageResult result = new PageResult();
        Object params = result.getParams();
        return new PageResult(200,"查询成功",params,page.getResult(),page.getTotal());
    }

    @Override
    public void add(Activity activity) {
        String randomString = UUID.randomUUID().toString().replaceAll("-", "").substring(0, 8);
        activity.setCode(randomString);
        activityMapper.add(activity);
    }

    @Override
    public Activity  findDetailAct(Integer id) {
        Activity activity=activityMapper.findDetailAct(id);
        return  activity;
    }

    @Override
    public void modifyAct(Activity activity) {
        activityMapper.modifyAct(activity);
    }

    @Override
    public void deleteAct(List<Integer> ids) {
        activityMapper.deleteAct(ids);
    }

    @Override
    public List<Activity> query(String channel) {
        List<Activity> list=activityMapper.query(channel);
        return list;
    }
}
